package cool.tianyou.blue.bird.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ApiResult<T> {
    public int getCode() {
        return code;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    /**
     * 返回码
     *
     * @see
     */
    private int code;

    /**
     * 是否成功
     */
    private boolean success;

    /**
     * 提示消息
     */
    private String message;

    /**
     * 返回实体
     */
    private T data;


    public static <T> ApiResult<T> success(T body) {
        return new ApiResult<>(200, true, "操作成功", body);
    }

    public static <T> ApiResult<T> success(T body, String message) {
        return new ApiResult<>(200, true, message, body);
    }

    public static <T> ApiResult<T> failed(T body) {
        return new ApiResult<>(200, false, "操作成功", body);
    }

    public static <T> ApiResult<T> failed(T body, String message) {
        return new ApiResult<>(200, false, message, body);
    }

    public static <T> ApiResult<T> isSuccess(T body, Boolean flag, String message) {
        return new ApiResult<>(200, flag, message, body);
    }
}
